package me.guitar.restweb.web;

import me.guitar.restweb.util.CookieUtil;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.random.R;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;

@IocBean
public class IndexController {
    @At("/hello")
    @Ok("raw")
    public String hello() {
        if(R.random(0,1) == 0){
            throw new RuntimeException("exception");
        }
        Mvcs.getHttpSession().setAttribute("hello","hello");
        return "<p>Hello Nutz</p>";
    }
    @At("/world")
    @Ok("raw")
    public String world() {
        return Mvcs.getHttpSession().getAttribute("hello").toString();
    }
    @At("/sc")
    public String sc(){
        CookieUtil.addCookie("jsessionId","123456789a",0);
        return "OK";
    }
    @At("/gc")
    public String gc(){
        return CookieUtil.getUid("jsessionId");
    }
}
